#region License
/* Copyright (c) 2011 Maksymilian Mulawa
	
Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:

   1. Redistributions of source code must retain the above copyright notice, 
 * this list of conditions and the following disclaimer.
   2. Redistributions in binary form must reproduce the above copyright notice, 
 * this list of conditions and the following disclaimer in the documentation 
 * and/or other materials provided with the distribution.
   3. The name of the author may not be used to endorse or promote products 
 * derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

using System.ComponentModel;
using System.Windows.Controls.WpfPropertyGrid;
using ReplicationExplorer.DomainModel.Infrastructure;
using ReplicationExplorer.DomainModel.Publisher.Entities;
using StringConverter = ReplicationExplorer.DomainModel.UI.StringConverter;

namespace ReplicationExplorer.DomainModel.Publisher.Models
{
    [CategoryOrder(PUBLISHER_CATEGORY,0)]
    [CategoryOrder(PUBLISHER_METADATA_CATEGORY, 1)]
    [CategoryOrder(PUBLICATIONS_CATEGORY, 2)]
    public class PublisherServerViewModel : TreeViewItemViewModel
    {
        private const string PUBLISHER_CATEGORY = "Publisher";
        private const string PUBLISHER_METADATA_CATEGORY = "Publisher metadata";
        private const string PUBLICATIONS_CATEGORY = "Publications";

        private readonly PublisherServer _publisherServer;

        public PublisherServerViewModel(PublisherServer publisherServer,
            PublisherServerFolderViewModel parent, bool lazyLoadChildren)
            : base(parent, lazyLoadChildren)
        {
            _publisherServer = publisherServer;
            Children.Add(new PublicationFolderViewModel(this, true));
        }

        public override string ModelViewIcon
        {
            get
            {
                return "PublisherServer.png";
            }
        }

        public override string ModelViewName
        {
            get
            {
                return "Publisher server";
            }
        }

        [Category(PUBLISHER_CATEGORY)]
        [Description("Sql Server instance name")]
        [DisplayName(@"Instance name")]
        [ReadOnly(true)]
        [PropertyOrder(0)]
        public string Name { get { return _publisherServer.Name; } }

        [Category(PUBLISHER_METADATA_CATEGORY)]
        [Description("Publisher type.")]
        [DisplayName(@"Publisher type")]
        [ReadOnly(true)]
        [PropertyOrder(1)]
        public string PublisherType { get { return _publisherServer.PublisherType; } }

        [Category(PUBLISHER_METADATA_CATEGORY)]
        [Description("Publisher Status.")]
        [DisplayName(@"Publisher Status")]
        [ReadOnly(true)]
        [PropertyOrder(2)]
        public string Status { get { return StringConverter.ConvertPublisherStatus(_publisherServer.Status); } }

        [Category(PUBLICATIONS_CATEGORY)]
        [Description("Publisher is active when it host at lest one publication.")]
        [DisplayName(@"Is active")]
        [ReadOnly(true)]
        [PropertyOrder(3)]
        public string IsActive { get { return StringConverter.ConvertBoolToYesNo(_publisherServer.IsActive); } }

        [Category(PUBLICATIONS_CATEGORY)]
        [Description("Folder where publication snapshots are being kept.")]
        [DisplayName(@"Snapshot folder")]
        [ReadOnly(true)]
        [PropertyOrder(4)]
        public string SnapshotFolder { get { return _publisherServer.SnapshotFolder; } }


        [Category(PUBLICATIONS_CATEGORY)]
        [Description("Publication count.")]
        [DisplayName(@"Publication count")]
        [ReadOnly(true)]
        [PropertyOrder(5)]
        public int PublicationCount { get { return _publisherServer.PublicationCount; } }

        [Category(PUBLICATIONS_CATEGORY)]
        [Description("Maximum threshold warning generated by a subscription belonging to a publication at this Publisher")]
        [DisplayName(@"Warning")]
        [ReadOnly(true)]
        [PropertyOrder(6)]
        public string Warning { 
            get
            {
                return StringConverter.ConvertPublisherWarning(_publisherServer.Warning);
            } 
        }

        [Browsable(false)]
        public PublisherServer Source
        {
            get {
                return _publisherServer;
            }
           
        }
    }

    
}